class AlarmRecord < ActiveRecord::Base
  self.table_name = "alarm_record"
 
  filterrific(
      available_filters: [
      :with_name,
      :with_phone,
      :with_status,
      :with_upload_time_begin,
      :with_upload_time_end,
                 ]
               )
  # default for will_paginate
  self.per_page = 5

  scope :with_name, lambda { |ref_name|
    return nil  if ref_name.blank?
    where('alarm_record.name like ?', '%' + ref_name.to_s + '%')
  }
  scope :with_phone, lambda { |ref_phone|
    return nil  if ref_phone.blank?
    where('alarm_record.phone like ?', '%' + ref_phone.to_s + '%')
  }
  scope :with_upload_time_begin, lambda { |upload_time_begin|
    return nil  if upload_time_begin.blank?
    where('alarm_record.created_at >= ?', upload_time_begin)
  }

  scope :with_upload_time_end, lambda { |upload_time_end|
    return nil  if upload_time_end.blank?
    where('alarm_record.created_at <= ?', upload_time_end)
  }
  
  scope :with_status, lambda { |ref_status|
    return nil  if ref_status.blank?
    where('alarm_record.status like ?', '%' + ref_status .to_s + '%')
  }

end
